<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Inc. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/documents
 */
class appdocsController extends appRain_Base_Core
{
    public $name = 'AppDocs';

    /**
     * This function will reander the home page
     *
     * @return null
     */
    public function indexAction($action='view',$id='')
    {
		$this->addons = array('syntaxhighlighter','addthis');
		$categoryData = Array();
		$cid= null;$scid = "";$cid = "";
		$page_content = $this->staticPageNameToMetaInfo('Docs');
		$this->set("page_content",$page_content);


		if($action == 'dppt')
		{
			$this->layout = 'empty';
			$post = App::InformationSet()->findById($id);
			$path = $this->basedir("/uploads/filemanager/{$post['ppt']}");
			App::Helper('Utility')->download($path,"{$post['title']}.ppt","application/ppt");

		}
		else if($action == 'dpdf')
		{
			$this->layout = 'empty';
			$post = App::InformationSet()->findById($id);
			$path = $this->basedir("/uploads/filemanager/{$post['pdf']}");
			App::Helper('Utility')->download($path,"{$post['title']}.pdf","application/pdf");

		}
		else if($action == 'dsc')
		{
			$this->layout = 'empty';
			$post = App::InformationSet()->findById($id);
			$path = $this->basedir("/uploads/filemanager/{$post['samplecode']}");
			App::Helper('Utility')->download($path,"{$post['title']}.zip","application/zip");

		}
        else if($action == 'c')
        {
            $categoryData = $this->CategorySet("docs-cat")
								 ->findById($id);
			$this->set("categoryData",$categoryData);
			$this->page_title = $categoryData['title'] . ' | appRain CMS and Framework Documentation';

			$posts = App::InformationSet("docs-post")->findAll(Array(Array('category'=>$id),"AND",Array('status'=>"Public")));
			$this->set("posts",$posts);

            $cid = ($categoryData['parent_id']!=0) ? $categoryData['parent_id'] : $id;
			$scid = $id;
        }

		$quicklist = App::InformationSet("docs-post")->findAll("1 ORDER BY generic ASC");
		$this->set("quicklist",$quicklist);

		if($action=='view')
		{
			$posts = App::InformationSet("docs-post")
					->setHLink($this->baseurl("/docs/view"))
					->setPage((is_numeric($id)?$id:1))
					->setSmartPaging('Yes')
					->setPagination('Yes')
					->setLimit(1)
					->findAll("1 ORDER BY generic ASC");
		}
		else if($action=='by-post')
		{
			$posts = App::InformationSet("docs-post")
						->setPagination('Yes')
						->findAll("id=$id");
						
			$this->page_title = $posts['data'][0]['title'];
		}

		$this->set('posts',$posts);

        $this->set("section_title","Video Tutorials");
        $this->set("selected","docs");
		$this->set("action",$action);
		$this->set("id",$id);
        $this->set("cid",$cid);
		$this->set("scid",$scid);
    }

	public function readonlineAction($id = NULL)
	{
		$this->addons = Array('flipper');

		$page_content = $this->staticPageNameToMetaInfo('Docs');
		$this->set("section_title","Official Documentation");
        $this->set("selected","docs");

		$slides = App::InformationSet("flipslideshow")->findAll(Array(Array('docs-post'=>$id),"AND",Array('status'=>"Public")));
		$this->set('slides',$slides);
		$this->set('id',$id);
	}
}
